package com.example.demo.service.impl;

import com.example.demo.service.IService;
import org.springframework.core.MethodParameter;
import org.springframework.core.annotation.SynthesizingMethodParameter;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.method.annotation.ModelFactory;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

/**
 * @author juntao.zhang
 * @version V1.0
 * @Description: TODO
 * @Package com.example.demo
 * @date 2018/4/12 21:49
 */
@RestController
public class ServiceImpl implements IService {

    @Override
    public List<String> show(List<String> names) {
        names.stream().forEach(System.err::println);
        return names;
    }

    public static void main(String[] args) {
        Class<?>[] interfaces = ServiceImpl.class.getInterfaces();
        Optional<Method> main = Arrays.stream(interfaces).map(inter -> {
            try {
                return inter.getDeclaredMethod("main", List.class);
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            }
            return null;
        }).filter(Objects::nonNull).findAny();
        MethodParameter methodParameter = SynthesizingMethodParameter.forMethodOrConstructor(main.get(), 0);

        String nameForParameter = ModelFactory.getNameForParameter(methodParameter);
        System.err.println(methodParameter);
        System.err.println(nameForParameter);


    }
}
